<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.thymeleaf.org/thymeleaf-extras-shiro">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>ComputerERP主页</title>
    <link rel="stylesheet" href="/static/js/layui/css/layui.css" media="all">
    <script type="text/javascript" src="/static/js/jquery/jquery-3.5.1.min.js"></script>
    <script type="text/javascript" src="/static/js/layui/layui.js"></script>
</head>
<body>
<div class="layui-layout layui-layout-admin">
    <!--    上方导航栏-->
    <div class="layui-header">
        <div class="layui-logo layui-hide-xs layui-bg-black"><a style="color: #E9E7E7" class="" th:href="@{/admin/main}">ComputerERP</a></div>
        <!-- 头部区域（可配合layui 已有的水平导航） -->
        <!--        <ul class="layui-nav layui-layout-left">-->
        <!--            &lt;!&ndash; 移动端显示 &ndash;&gt;-->
        <!--            <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-header-event="menuLeft">-->
        <!--                <i class="layui-icon layui-icon-spread-left"></i>-->
        <!--            </li>-->

        <!--            <li class="layui-nav-item layui-hide-xs"><a href="">nav 1</a></li>-->
        <!--            <li class="layui-nav-item layui-hide-xs"><a href="">nav 2</a></li>-->
        <!--            <li class="layui-nav-item layui-hide-xs"><a href="">nav 3</a></li>-->
        <!--            <li class="layui-nav-item">-->
        <!--                <a href="javascript:;">nav groups</a>-->
        <!--                <dl class="layui-nav-child">-->
        <!--                    <dd><a href="">menu 11</a></dd>-->
        <!--                    <dd><a href="">menu 22</a></dd>-->
        <!--                    <dd><a href="">menu 33</a></dd>-->
        <!--                </dl>-->
        <!--            </li>-->
        <!--        </ul>-->
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item layui-hide layui-show-md-inline-block">
<!--                <a href="javascript:;">-->
<!--&lt;!&ndash;                    <img src="//tva1.sinaimg.cn/crop.0.0.118.118.180/5db11ff4gw1e77d3nqrv8j203b03cweg.jpg" class="layui-nav-img">&ndash;&gt;-->
<!--                    tester-->
<!--                </a>-->
<!--                <dl class="layui-nav-child">-->
<!--                    <dd><a th:href="@{/main/selfinformation}">个人信息</a></dd>-->
<!--                    <dd><a href="">退出登录</a></dd>-->
<!--                </dl>-->
            </li>
            <li class="layui-nav-item" lay-header-event="menuRight" lay-unselect>
                <a href="javascript:;">
                    <i class="layui-icon layui-icon-more-vertical"></i>
                </a>
            </li>
        </ul>
    </div>
    <!--左侧导航栏-->
    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="test">
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="javascript:;">进货管理</a>
                    <dl class="layui-nav-child">
                        <dd><a th:href="@{/main/purchase/pmanagement}">进货入库</a></dd>
                        <dd><a th:href="@{/main/purchase/omanagement}">退货出库</a></dd>
                        <dd><a th:href="@{/main/purchase/pmanagementorder}">进货单查询</a></dd>
                        <dd><a th:href="@{/main/purchase/omanagementorder}">退货单查询</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item ">
                    <a href="javascript:;">销售管理</a>
                    <dl class="layui-nav-child">
                        <dd><a th:href="@{/main/sales/salesdelivery}">销售出库</a></dd>
                        <dd><a th:href="@{/main/sales/omanagement}">客户退货</a></dd>
                        <dd><a th:href="@{/main/sales/salesorder}">销售单查询</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item ">
                    <a class="" href="javascript:;">库存管理</a>
                    <dl class="layui-nav-child">
                        <dd><a th:href="@{/main/warehouse/damage}">商品报损/报溢</a></dd>
                        <dd><a th:href="@{/main/warehouse/alarm}">库存报警</a></dd>
                        <dd><a th:href="@{/main/warehouse/brimordamage}">报损报溢查询</a></dd>
                        <dd><a th:href="@{/main/warehouse/querywarehouse}">当前库存查询</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a class="" th:href="@{/main/report/report}">统计报表</a>
                <li class="layui-nav-item ">
                    <a class="" th:href="@{/main/manage/manage}">系统设置</a>
                </li>
            </ul>
        </div>
    </div>
    <!--主体区域-->
    <!--    <div class="layui-body">-->
    <!--        &lt;!&ndash; 内容主体区域 &ndash;&gt;-->
    <!--&lt;!&ndash;        <div style="padding: 15px;">内容主体区域。记得修改 layui.css 和 js 的路径</div>&ndash;&gt;-->
    <!--    </div>-->

    <div class="layui-tab layui-tab-brief">
        <div class="layui-body layui-tab-content"style="background-image: url(/static/images/bg2.jpg); height: 930px; background-repeat: no-repeat; ">
            <div class="layui-tab-item layui-show">
                <div class="layui-main">
                    <div style="margin:0 auto; max-width: 1140px;">
                        <div class="layui-col-md6 layui-col-md-offset3">
                            <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
                                <legend>下达进货订单</legend>
                            </fieldset>

<!--                            layui.use('form', function(){-->
<!--                            var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功-->

<!--                            //……-->

<!--                            //如果你的 HTML 是动态生成的，自动渲染就会失效-->
<!--                            //因此你需要在相应的地方，执行下述方法来进行渲染-->
<!--                            form.render();-->
<!--                            });-->

                            <form class="layui-form" action="">
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 100px">选择进货零件</label>
                                    <div class="layui-input-inline " id="selectLingJianName" style="overflow: visible">
                                        <select name="modules" class="selectLingJianName" lay-verify="required" lay-search="">
                                            <option value="">直接选择或搜索选择</option>
                                            <option value="1">零件1</option>
                                            <option value="2">零件2</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 100px">选择进货商家</label>
                                    <div class="layui-input-inline " id="selectMerchantName" style="overflow: visible">
                                        <select name="modules" class="selectMerchantName" lay-verify="required" lay-search="">
                                            <option value="">直接选择或搜索选择</option>
                                            <option value="1">商家1</option>
                                            <option value="2">商家2</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 100px">输入进货数量</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="number" id="number" lay-verify="number" autocomplete="off" placeholder="输入进货数量" class="layui-input">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 100px">最迟进货日期</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="date" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label" style="width: 100px">选择负责人</label>
                                    <div class="layui-input-inline " id="selectUserName" style="overflow: visible">
                                        <select name="modules" class="selectUserName" lay-verify="required" lay-search="">
                                            <option value="">直接选择或搜索选择</option>
                                            <option value="1">进货员1</option>
                                            <option value="2">进货员2</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-md-offset4">
                                <button type="button" id="insertOrder" class="layui-btn layui-btn-fluid layui-btn-radius">下达订单</button>
                            </div>
                        </form>
                        </div>
                        <!--                            这里写主体内容-->
<!--                            layui-col-md 占据空间-->
<!--                            layui-col-md-offset 偏移空间-->
<!--                            <div class="layui-col-md10 layui-col-md-offset1">-->
<!--                            </div>-->
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    //JS
    layui.use(['element', 'layer', 'util','laydate','form'], function(){
        var element = layui.element
            ,layer = layui.layer
            ,util = layui.util
            ,laydate = layui.laydate
            ,$ = layui.$;
            // , form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成

        // layui.use('form', function(){
        //     var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成
        //     form.render();
        // });

        //日期
        laydate.render({
            elem: '#date'
        });
        // laydate.render({
        //     elem: '#date1'
        // });

        //头部事件
        util.event('lay-header-event', {
            //左侧菜单事件
            menuLeft: function(othis){
                layer.msg('展开左侧菜单的操作', {icon: 0});
            }
            ,menuRight: function(){
                layer.open({
                    type: 1
                    ,content: '<div style="padding: 15px;">处理右侧面板的操作</div>'
                    ,area: ['260px', '100%']
                    ,offset: 'rt' //右上角
                    ,anim: 5
                    ,shadeClose: true
                });
            }
        });
    });
    $(function () {
        //请求数据
        shuaxin();

        function shuaxin(){
            $.ajax({
                url:'/main/purchase/login/pmanagement',
                type:'post',
                dataType:'json',
                success:function(data){
                    $('#selectLingJianName').empty();//清空selectLingJianName内容
                    console.log(data);
                    let select1 =  '<select name="modules" class="selectLingJianName" lay-verify="required" lay-search="">';
                    select1 += '<option value="99">直接选择或搜索选择</option>';
                    for (let i = 0; i < data.lingjianname.length; i++){
                        select1 += '<option value='+i+'>'+data.lingjianname[i]+'</option>';
                        console.log(data.lingjianname[i]);
                    }
                    select1 += '</select>';
                    $("#selectLingJianName").append(select1);//更新获取到的零件名

                    $('#selectMerchantName').empty();//清空selectMerchantName
                    let select2 =  '<select name="modules" class="selectMerchantName" lay-verify="required" lay-search="">';
                    select2 += '<option value="99">直接选择或搜索选择</option>';
                    for (let i = 0; i < data.merchantname.length; i++){
                        select2 += '<option value='+i+'>'+data.merchantname[i]+'</option>';
                        console.log(data.merchantname[i]);
                    }
                    select2 += '</select>';
                    $("#selectMerchantName").append(select2);//更新获取到的员工名称

                    $('#selectUserName').empty();//selectUserName
                    let select3 =  '<select name="modules" class="selectUserName" lay-verify="required" lay-search="">';
                    select3 += '<option value="99">直接选择或搜索选择</option>';
                    for (let i = 0; i < data.userName.length; i++){
                        select3 += '<option value='+i+'>'+data.userName[i]+'</option>';
                        console.log(data.userName[i]);
                    }
                    select3 += '</select>';
                    $("#selectUserName").append(select3);//更新获取到的员工名称

                    renderForm();
                },
                error:function(){
                }
            });
        }
        //信息提交
        $("#insertOrder").click(function(){
            if ($(".selectLingJianName").find("option:selected").text()=="直接选择或搜索选择"){
                layer.msg('请选择零件名！');
                return;
            }
            if ($(".selectMerchantName").find("option:selected").text()=="直接选择或搜索选择"){
                layer.msg('请选择供货商名称！');
                return;
            }
            if (!($("#number").val())){
                layer.msg('请填写商品数量！');
                return;
            }
            if (!($("#date").val())){
                layer.msg('请选择交付截止日期！');
                return;
            }
            if ($(".selectUserName").find("option:selected").text()=="直接选择或搜索选择"){
                layer.msg('请选负责人！');
                return;
            }
            var param = {"LingJianName":$(".selectLingJianName").find("option:selected").text(),"MerchantName":$(".selectMerchantName").find("option:selected").text(),"number":$("#number").val(),"date":$("#date").val(),"username":$(".selectUserName").find("option:selected").text()};
            console.log(param);
            $.ajax({
                url:'/main/purchase/insertPurchaseOrder',
                type:'post',
                data:param,
                dataType:'json',
                success:function(data){
                    // console.log(data);
                    if(data.result == 1){
                        layer.msg('下单成功！');

                    }else if (data.result == 2){
                        layer.msg('数量太多超出仓库上限！');
                    }else if (data.result == 3){
                        layer.msg('该零件已经过多！');
                    }else{
                        layer.msg('未指名的错误呢！');
                    }
                    setTimeout(function (){
                        location.reload();
                    },1500);
                },
                error:function(){
            }
        });

        });

        function renderForm() {
            layui.use('form', function () {
                var form = layui.form;
                form.render();
            });
        }

    });

</script>
</body>
</html>